<?php
namespace app\index\controller;

use think\Controller;
use app\common\service\Http;

class Index extends Controller
{
    public $appID = 'wx3c182dde218434b4';//小程序账号
    public $secret = '6d4cdf15a24ab9b003d93a287cec62ab';
    public $_http;
    
    public function _initialize() {
        $this->_http = new Http();
    }
    
    public function index()
    {
        echo '&lt;script&gt;alert(1111)&lt;/script&gt;';die;
        //return $this->fetch();
    }
    
    public function get_user()
    {
        $code = input('code');
        $nickName = input('nickName');
        $avatarUrl = input('avatarUrl');
        
        //$code = '033EdaML1eymG51fYrKL1wwSLL1EdaMH';
        $url = 'https://api.weixin.qq.com/sns/jscode2session?appid='.$this->appID.'&secret='.$this->secret.'&js_code='.$code.'&grant_type=authorization_code';
        
        $res_data = json_decode($this->_http->get($url),true);
        //dump($res_data);
        $data = array('open_id'=>$res_data['openid'],'nickName'=>$nickName,'avatarUrl'=>$avatarUrl);
        echo json_encode(array('data'=>$data));die;
    }
}
